import { toRefs, ref } from 'vue'
import { getDictDataPage } from '@views/dictManage/api/dictManage'

// 获取字典数据

export function useDict (...args) {
  const res = ref({})
  return (() => {
    args.forEach((dictType, index) => {
      res.value[dictType] = []
      // dictType字典名称
      getDictDataPage({ classifyCode: dictType }).then(resp => {
        res.value[dictType] = resp.data.lookupItemList.map(p => ({ label: p.itemName, value: p.itemCode, tagType: p.tagType || null }))
      })
    })
    return toRefs(res.value)
  })()
}

// 全局挂载字典
export function setupDicts (app) {
  app.config.globalProperties.useDict = useDict
}
